package com.datamanage.user.repository;

import com.datamanage.user.entity.Group;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
public interface GroupRepository extends JpaRepository<Group, Long> {
    Optional<Group> findByName(String name);
    
    Boolean existsByName(String name);
    
    @Query("SELECT g FROM Group g JOIN FETCH g.permissions WHERE g.id = :id")
    Optional<Group> findByIdWithPermissions(@Param("id") Long id);
    
    @Query("SELECT g FROM Group g JOIN FETCH g.users WHERE g.id = :id")
    Optional<Group> findByIdWithUsers(@Param("id") Long id);
}